package com.qianya.oa.config;

import com.qianya.oa.common.config.QianYaConfig;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger3的接口配置
 * 
 * @author qianya
 */
@Configuration
@Profile({"dev", "test"})
public class SwaggerConfig
{

    @Bean
    public Docket restApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("oa")
//                // 配置swagger3 jwt token
//                .securitySchemes(Collections.singletonList(HttpAuthenticationScheme.JWT_BEARER_BUILDER
//                        // 显示用
//                        .name("JWT")
//                        .build()))
//                .securityContexts(Collections.singletonList(SecurityContext.builder()
//                        .securityReferences(Collections.singletonList(SecurityReference.builder()
//                                .scopes(new AuthorizationScope[0])
//                                .reference("JWT")
//                                .build()))
//                        // 声明作用域
//                        .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
//                        .build()))
                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.qianya.oa.controller"))
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("谦雅科技API接口").version("1.0").build();
    }
}
